<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 500px;
            height: 300px;
            text-align: center;
            font-size: 26px;
            padding-top: 200px;
            background-color: dimgray;
            color: pink;
            margin: 100px auto;
        }
    </style>
</head>

<body>
    <button>首页</button>
    <button>服务</button>
    <button>中心</button>
    <div></div>
</body>

</html>
<script>
    // 定义一个路由表
    let routes = [
        { path: '/home', method: home_page },
        { path: '/service', method: service_page },
        { path: '/mine', method: mine_page }
    ]
    // 各自不同的函数，给页面渲染内容
    function home_page() {
        div.innerHTML = '我是首页，，是你们的老大，你们逗得听我的'
    }
    function service_page() {
        div.innerHTML = '我是服务，，我才是你们的老大，你们逗得听我的'
    }
    function mine_page() {
        div.innerHTML = '我是个人中心，，是你们的自己，你们逗得听我的'
    }
    let btns = [...document.querySelectorAll('button')]
    let div = document.querySelector('div')
    console.log(btns);
    
    btns.forEach((item, index) => {
        item.onclick = function (e) {
            history.pushState({}, '', routes[index].path)
            routes[index].method();
        }
    })
</script>